package com.aiyige.track;

import android.content.Context;

import com.baidu.mobstat.StatService;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 埋点
 * Created by zhuyakun on 2018/2/25.
 */

public class TrackEvent {
    public static final String CANCEL_SELECT_LEARN_VIDEO ="cancel_select_learn_video";
    public static final String CANCEL_SELECT_LEARN_VIDEO_EDIT ="cancel_select_learn_video_edit";
    public static final String UNSELECT_LEARN_VIDEO_SUB_COVER ="unselect_learn_video_sub_cover";
    public static final String LEARN_VIDEO_TRAIL_FIRST ="learn_video_trail_first";
    public static final String LEARN_VIDEO_PREVIEW ="learn_video_preview";
    public static final String SELECT_LEARN_VIDEO_COVER_TYPE ="select_learn_video_cover_type";
    public static final String FIN_SELECT_LEARN_VIDEO_COVER ="fin_select_learn_video_cover";
    public static final String CANCEL_PUBLISH_LEARN_VIDEO ="cancel_publish_learn_video";
    public static final String LEARN_VIDEO_ADD_TAG ="learn_video_add_tag";
    public static final String LEARN_VIDEO_MODIFY_SPLIT_VIDEO ="learn_video_modify_split_video";
    public static final String LEARN_VIDEO_MOD_SUB_VIDEO_ACT ="learn_video_mod_sub_video_act";
    public static final String LEARN_VIDEO_PUBLISH_TYPE ="learn_video_publish_type";
    public static final String LEARN_VIDEO_PUBLISH_FINISH ="learn_video_publish_finish";
    public static final String LEARN_VIDEO_MOD_COL_TYPE_EDIT ="learn_video_mod_col_type_edit";
    public static final String LEARN_VIDEO_MOD_SUB_ACT_EDIT ="learn_video_mod_sub_act_edit";
    public static final String LEARN_VIDEO_PUBLISH_FAILED ="learn_video_publish_failed";
    public static final String LEARN_VIDEO_PUBLISH_DURATION ="learn_video_publish_duration";
    public static final String DEL_PUBLISHING_LEARN_VIDEO_DUR ="del_publishing_learn_video_dur";
    public static final String LEARN_VIDEO_STATUS_REJ_TO_PUB ="learn_video_status_rej_to_pub";
    public static final String DELETE_LEARN_VIDEO_STATUS ="delete_learn_video_status";
    public static final String UNPUB_LEARN_VIDEO_PUB_METHOD ="unpub_learn_video_pub_method";
    public static final String PUBLISH_LEARN_VIDEO_EDIT ="publish_learn_video_edit";
    public static final String DETAIL_PAGE_BUY ="detail_page_buy";
    public static final String CONFIRM_ORDER ="confirm_order";
    public static final String CONFIRM_PAY ="confirm_pay";
    public static final String PAY_SUCCESS ="pay_success";
    public static final String MY_BUY_LEARN_VIDEO_VIEW_DATE ="my_buy_learn_video_view_date";
    public static final String MY_FAVORITE_CONTENT_VIEW_DATE ="my_favorite_content_view_date";
    public static final String MY_VIEW_CONTENT_VIEW_HOW_LONG ="my_view_content_view_how_long";
    public static final String MY_CACHE_FINISH_NUM ="my_cache_finish_num";
    public static final String MY_CACHE_PAUSE_NUM ="my_cache_pause_num";
    public static final String DELETE_MY_UNFINISH_CACHE ="delete_my_unfinish_cache";
    public static final String MY_COMMENT_MSG_REPLY_SUCCESS ="my_comment_msg_reply_success";
    public static final String GLOBAL_SEARCH_METHOD ="global_search_method";
    public static final String CANCEL_SELECT_NORMAL_VIDEO ="cancel_select_normal_video";
    public static final String UNSELECT_NORMAL_VIDEO_EDIT ="unselect_normal_video_edit";
    public static final String UNSEL_NORMAL_VIDEO_SUB_COVER ="unsel_normal_video_sub_cover";
    public static final String NORMAL_VIDEO_PREVIEW ="normal_video_preview";
    public static final String SELECT_NORMAL_VIDEO_COVER_TYPE ="select_normal_video_cover_type";
    public static final String FIN_SELECT_NORMAL_VIDEO_COVER ="fin_select_normal_video_cover";
    public static final String CANCEL_PUBLISH_NORMAL_VIDEO ="cancel_publish_normal_video";
    public static final String NORMAL_VIDEO_ADD_TAG ="normal_video_add_tag";
    public static final String NORMAL_VIDEO_MOD_SPLIT_VIDEO ="normal_video_mod_split_video";
    public static final String NORMAL_VIDEO_MOD_SUB_VIDEO_ACT ="normal_video_mod_sub_video_act";
    public static final String NORMAL_VIDEO_ADD_RECORD_VIDEO ="normal_video_add_record_video";
    public static final String NORMAL_VIDEO_ADD_NO_REC_VIDEO ="normal_video_add_no_rec_video";
    public static final String PUBLISH_NORMAL_VIDEO_NUM ="publish_normal_video_num";
    public static final String PUBLISH_NORMAL_VIDEO_SIZE ="publish_normal_video_size";
    public static final String PUBLISH_PHOTO_NUM ="publish_photo_num";
    public static final String PUBLISH_PHOTO_VIDEO_NUM ="publish_photo_video_num";
    public static final String DELETE_PUBLISHING_DYNAMIC ="delete_publishing_dynamic";
    public static final String DELETE_PUBLISHED_DYNAMIC ="delete_published_dynamic";

    public static final String CANCEL_SELECT_LEARN_VIDEO_LABEL ="取消选择教学视频";
    public static final String CANCEL_SELECT_LEARN_VIDEO_EDIT_LABEL ="编辑时取消选择教学视频";
    public static final String UNSELECT_LEARN_VIDEO_SUB_COVER_LABEL ="取消选择教学视频子视频封面";
    public static final String LEARN_VIDEO_TRAIL_FIRST_LABEL ="是否选择第一集作为试看";
    public static final String LEARN_VIDEO_PREVIEW_LABEL ="预览教学视频";
    public static final String SELECT_LEARN_VIDEO_COVER_TYPE_LABEL ="选择的教学视频封面的类型";
    public static final String FIN_SELECT_LEARN_VIDEO_COVER_LABEL ="完成选择教学视频子视频封面";
    public static final String CANCEL_PUBLISH_LEARN_VIDEO_LABEL ="取消发布教学视频";
    public static final String LEARN_VIDEO_ADD_TAG_LABEL ="教学视频添加标签";
    public static final String LEARN_VIDEO_MODIFY_SPLIT_VIDEO_LABEL ="修改教学视频分集视频";
    public static final String LEARN_VIDEO_MOD_SUB_VIDEO_ACT_LABEL ="修改教学视频分集视频动作";
    public static final String LEARN_VIDEO_PUBLISH_TYPE_LABEL ="教学视频的发布类型";
    public static final String LEARN_VIDEO_PUBLISH_FINISH_LABEL ="教学视频发布量";
    public static final String LEARN_VIDEO_MOD_COL_TYPE_EDIT_LABEL ="编辑时教学视频修改项目";
    public static final String LEARN_VIDEO_MOD_SUB_ACT_EDIT_LABEL ="编辑时修改教学视频分集视频";
    public static final String LEARN_VIDEO_PUBLISH_FAILED_LABEL ="发布教学视频失败";
    public static final String LEARN_VIDEO_PUBLISH_DURATION_LABEL ="教学视频发布时长";
    public static final String DEL_PUBLISHING_LEARN_VIDEO_DUR_LABEL ="被删除的上传中教学视频的上传时长";
    public static final String LEARN_VIDEO_STATUS_REJ_TO_PUB_LABEL ="教学视频审核未通过转化为已发布";
    public static final String DELETE_LEARN_VIDEO_STATUS_LABEL ="删除的教学视频状态";
    public static final String UNPUB_LEARN_VIDEO_PUB_METHOD_LABEL ="未发布教学视频的发布方式";
    public static final String PUBLISH_LEARN_VIDEO_EDIT_LABEL ="已发布教学视频编辑后发布";
    public static final String DETAIL_PAGE_BUY_LABEL ="详情页立即购买";
    public static final String CONFIRM_ORDER_LABEL ="确认订单";
    public static final String CONFIRM_PAY_LABEL ="确认支付";
    public static final String PAY_SUCCESS_LABEL ="最终付款";
    public static final String MY_BUY_LEARN_VIDEO_VIEW_DATE_LABEL ="多久之前查看了我的已买的教学视频";
    public static final String MY_FAVORITE_CONTENT_VIEW_DATE_LABEL ="多久之前查看了我的收藏里面的内容";
    public static final String MY_VIEW_CONTENT_VIEW_HOW_LONG_LABEL ="多久之前查看了我的浏览里面的内容";
    public static final String MY_CACHE_FINISH_NUM_LABEL ="我的缓存完成数量";
    public static final String MY_CACHE_PAUSE_NUM_LABEL ="我的缓存暂停数量";
    public static final String DELETE_MY_UNFINISH_CACHE_LABEL ="删除未完成的缓存";
    public static final String MY_COMMENT_MSG_REPLY_SUCCESS_LABEL ="评论消息页面回复成功";
    public static final String GLOBAL_SEARCH_METHOD_LABEL ="全局搜索方式";
    public static final String CANCEL_SELECT_NORMAL_VIDEO_LABEL ="取消选择普通视频";
    public static final String UNSELECT_NORMAL_VIDEO_EDIT_LABEL ="编辑时取消选择普通视频";
    public static final String UNSEL_NORMAL_VIDEO_SUB_COVER_LABEL ="取消选择普通视频子视频封面";
    public static final String NORMAL_VIDEO_PREVIEW_LABEL ="预览普通视频";
    public static final String SELECT_NORMAL_VIDEO_COVER_TYPE_LABEL ="选择的普通视频封面的类型";
    public static final String FIN_SELECT_NORMAL_VIDEO_COVER_LABEL ="完成选择普通视频子视频封面";
    public static final String CANCEL_PUBLISH_NORMAL_VIDEO_LABEL ="取消发布普通视频";
    public static final String NORMAL_VIDEO_ADD_TAG_LABEL ="普通视频添加标签";
    public static final String NORMAL_VIDEO_MOD_SPLIT_VIDEO_LABEL ="修改普通视频分集视频";
    public static final String NORMAL_VIDEO_MOD_SUB_VIDEO_ACT_LABEL ="修改普通视频分集视频动作";
    public static final String NORMAL_VIDEO_ADD_RECORD_VIDEO_LABEL ="添加拍摄视频";
    public static final String NORMAL_VIDEO_ADD_NO_REC_VIDEO_LABEL ="添加已有视频";
    public static final String PUBLISH_NORMAL_VIDEO_NUM_LABEL ="普通视频集束";
    public static final String PUBLISH_NORMAL_VIDEO_SIZE_LABEL ="普通视频每集大小";
    public static final String PUBLISH_PHOTO_NUM_LABEL ="发布图集中图片的数量";
    public static final String PUBLISH_PHOTO_VIDEO_NUM_LABEL ="发布文章中包含的图片视频数量";
    public static final String DELETE_PUBLISHING_DYNAMIC_LABEL ="删除发布中的动态";
    public static final String DELETE_PUBLISHED_DYNAMIC_LABEL ="删除已发布的动态";



    List<String> eventIdList = new LinkedList<>();

    public TrackEvent() {
    }

    public void sendEvent(Context context, String eventId, String eventLabel) {
        sendEvent(context, eventId, eventLabel, false);
    }

    public void sendEvent(Context context, String eventId, String eventLabel, Map<String, String> attrs) {
        sendEvent(context, eventId, eventLabel, attrs, false);
    }


    public void sendEvent(Context context, String eventId, String eventLabel, boolean singleTrack) {
        if (singleTrack && eventIdList.contains(eventId)) return;
        if (!eventIdList.contains(eventId)) {
            eventIdList.add(eventId);
        }
        StatService.onEvent(context, eventId, eventLabel);
    }

    public void sendEvent(Context context, String eventId, String eventLabel, Map<String, String> attrs, boolean singleTrack) {
        if (singleTrack && eventIdList.contains(eventId)) return;
        if (!eventIdList.contains(eventId)) {
            eventIdList.add(eventId);
        }
        StatService.onEvent(context, eventId, eventLabel, 1, attrs);
    }
}
